<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        (function (list) {
            function require(file) {
                var exports = {};
                (function (exports, code) {
                    eval(code)
                })(exports, list[file]);
                return exports
            }
            // 入口
            require('index.js')
        })({
            "index.js": `
             var add = require('add.js').default;
             console.log(add(1, 5));`,
            "add.js": "var a = 123;exports.default = function (a, b){return a + b}"
        });

        /*
        由index.js入口执行require()函数，第一次file为'index.js'，value值 `var add = require('add.js').default;console.log(add(1, 5));`
        执行value的时候用eval又执行了导入add.js，第二次file为'add.js'，value值为 "var a = 123;exports.default = function (a, b){return a + b}"
        */

        /*
        1.收集依赖 谁影响谁
        2.ES6转ES5
        3.替换require与exports
        */
    </script>
</body>

</html>